
class Main extends eui.UILayer {
    private loadingView:LoadingView;
    
    public constructor() {
        super();
        this.addEventListener(egret.Event.ADDED_TO_STAGE,this.addToStage,this);
    }
     
    /**
     * 添加到舞台
     */
    private addToStage(event: egret.Event) {
        this.removeEventListener(egret.Event.ADDED_TO_STAGE,this.addToStage,this);
        this.stage.registerImplementation("eui.IAssetAdapter",new AssetAdapter());
        this.stage.registerImplementation("eui.IThemeAdapter",new ThemeAdapter());

        if(DeviceUtils.isPC) {
            var stageScene: StageScene = StageScene.getInstance()
            stageScene.setScaleMode(egret.StageScaleMode.SHOW_ALL);
        } 
        this.loadingView = new LoadingView();
        this.loadingView.setProgress(7,14);
        StageScene.get.getUIStage().addChild(this.loadingView);
        
        /** 加载配置项 */
        ResManager.get.addConfig("resource/default.res.json","resource/");
        ResManager.get.addConfig("resource/main.res.json","resource/");
        ResManager.get.loadConfig(this.onConfigComplete,this);
    }
    
    /**
     * 配置文件加载完成,开始预加载preload资源组。
     * configuration file loading is completed, start to pre-load the preload resource group
     */
    private onConfigComplete(): void {
        /** 加载主题 */
        var theme = new eui.Theme("resource/default.thm.json",this.stage);
        theme.addEventListener(eui.UIEvent.COMPLETE,this.onThemeLoadComplete,this);
    }

    private onThemeLoadComplete() {
        ResManager.get.loadGroup("splash",this.onResourceLoadComplete,this.onResourceProgress,this);
    }
    
    /**
     * preload资源组加载完成
     * Preload resource group is loaded
     */
    private onResourceLoadComplete(groupName: string): void {
        if(groupName == "splash") {
            this.createGameScene();
        } else if(groupName == "main") {

        }
    }
    
    /**
     * preload资源组加载进度
     * Loading process of preload resource group
     */
    private onResourceProgress(progress: number,total: number): void {
        this.loadingView.setProgress(progress,total);
    }

    /**
     * 创建游戏场景
     * Create a game scene
     */
    private createGameScene(): void {
        this.loadingView.setBgRes("game_main_bg_png");
    }

}


